package com.breeze.blockchain.task;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.xxl.job.core.handler.annotation.XxlJob;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author breeze
 */
@Component
@Slf4j
public class ScheduleJobManager {

  @XxlJob("test1Handler")
  public void test1Handler() {
    log.info(
        "test1Handler 5s执行一次 Current Thread : {}, Fixed Rate Task : The time is now {}",
        Thread.currentThread().getName(),
        DateUtil.formatTime(new Date()));
  }

  @XxlJob("test2Handler")
  public void test2Handler() {
    log.info("test2Handler 耗时任务start...");
    ThreadUtil.sleep(7000);
    log.info(
        "test2Handler 10s执行一次耗时7s的任务 Current Thread : {}, Fixed Rate Task : The time is now {}",
        Thread.currentThread().getName(),
        DateUtil.formatTime(new Date()));
  }

  @XxlJob("test3Handler")
  public void test3Handler() {
    log.info(
        "test3Handler 1s执行一次任务 Current Thread : {}, Fixed Rate Task : The time is now {}",
        Thread.currentThread().getName(),
        DateUtil.formatTime(new Date()));
  }

  @XxlJob("test4Handler")
  public void test4Handler() {
    log.info("test4Handler 耗时任务start...");
    ThreadUtil.sleep(15000);
    log.info(
        "test4Handler 10s执行一次耗时15s的任务 Current Thread : {}, Fixed Rate Task : The time is now {}",
        Thread.currentThread().getName(),
        DateUtil.formatTime(new Date()));
  }
}
